package cn.zhangtiancinb.simple_demo.exception_switch.server;

import java.util.Map;
import java.util.Collection;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.zhangtiancinb.simple_demo.exception_switch.client.ExceptionSwitchUtil;

/**
 * 后台接口
 *
 * @author 张天赐
 */
@RestController
@RequestMapping("/api")
public class ApiController {
    @Resource
    ExceptionSwitchUtil exceptionSwitchUtil;

    /**
     * 读取开关
     *
     * @return 开关状态
     */
    @RequestMapping("read")
    public Map<String, Boolean> read() {
        return exceptionSwitchUtil.read();
    }

    /**
     * 更新开关信息
     *
     * @param data 开关信息
     */
    @RequestMapping("write")
    public void write(@RequestBody Map<String, Boolean> data) {
        exceptionSwitchUtil.write(data);
    }

    /**
     * 获取所有相关的Key
     */
    @RequestMapping("keys")
    public Collection<String> keys() {
        return exceptionSwitchUtil.keys();
    }
}
